package com.actionpals.net
{
	import flash.net.URLRequest;
	import flash.net.URLRequestMethod;
	
	public class URL
	{
		private var _location:String;
		private var _GETVariables:Array;
		private var _POSTVariables:Array;
		private var _request:URLRequest;
		
		public function URL( location:String=null )
		{
			_location = location;
			_GETVariables = new Array();
			_POSTVariables = new Array();
			_request = new URLRequest();
		}
		
		public function get location():String
		{
			return _location;
		}
		public function set location( value:String ):void
		{
			_location = value;
		}
		
		public function get GETVariables():Array
		{
			return _GETVariables;
		}
		
		public function get POSTVariables():Array
		{
			return _POSTVariables;
		}
		
		public function get request():URLRequest
		{
			var url:String = location;
			for( var i:int = 0; i<GETVariables.length; i++ )
			{
				if( i == 0 ) url += "?";
				url += URLVariable( GETVariables[i] ).name;
				url += "=";
				url += URLVariable( GETVariables[i] ).value;
				if( i < GETVariables.length - 1 ) url += "&";
			}
			_request.url = url;
			
			if( POSTVariables.length > 0 )
			{
				var urlVariables:com.actionpals.net.URLVariables = new URLVariables();
				for( i = 0; i<POSTVariables.length; i++ )
				{
					urlVariables[ URLVariable( POSTVariables[i] ).name ] = URLVariable( POSTVariables[i] ).value;
				}
				_request.data = urlVariables;
				_request.method = URLRequestMethod.POST;
			}
			
			return _request;
		}

	}
}
